package saucaca.fragment;

import java.util.ArrayList;

import lemon.kenhnhacvn.R;
import saucaca.Adapter.ExpandableSongAdapter;
import saucaca.CustomView.CircularImageView;
import saucaca.CustomView.CustomExpandableListView;
import saucaca.Object.AlbumObject;
import saucaca.Object.SongObject;
import saucaca.Util.TagName;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class AlbumDetaisContent extends Fragment {
	AlbumObject albumObject;
	Context context;
	DisplayImageOptions options;
	String albumID = "";
	TextView txtTitle, txtArtist;
	CircularImageView albumPic;
	private CustomExpandableListView expandView;
	ArrayList<SongObject> listSongs;
	ExpandableSongAdapter adapter;
	public AlbumDetaisContent(Context context, AlbumObject albumObject, ArrayList<SongObject> listSongs) {
		this.albumObject = albumObject;
		this.context = context;
		this.listSongs = listSongs;
	}

	public void update(AlbumObject albumObject, ArrayList<SongObject> listSongs) {
		this.albumObject = albumObject;
		this.listSongs = listSongs;
		showAlbumDetail(albumObject);
	}

	@SuppressWarnings("deprecation")
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.album_details_main, container, false);
		options = new DisplayImageOptions.Builder().showImageOnFail(R.drawable.ic_default).showStubImage(R.drawable.ic_default).showImageForEmptyUri(R.drawable.ic_default)
				.cacheInMemory().cacheOnDisc().build();
		findviewbyid(view);
		showAlbumDetail(albumObject);
		return view;
	}

	public void findviewbyid(View view) {
		albumPic = (CircularImageView) view.findViewById(R.id.album_details_picture);
		txtArtist = (TextView) view.findViewById(R.id.album_details_txtArtist);
		txtTitle = (TextView) view.findViewById(R.id.album_details_txtTitle);
		expandView = (CustomExpandableListView) view.findViewById(R.id.expandableListView1);
		expandView.setExpanded(true);
	}

	void showAlbumDetail(AlbumObject albumObject) {
		ImageLoader.getInstance().displayImage(albumObject.getAVATAR(), albumPic, options);
		txtTitle.setText(albumObject.getTXNAME());
		txtArtist.setText(albumObject.getSEO_NAME());
		if (listSongs != null && expandView != null)
			if (adapter==null) {
				TagName.showLogError("Album", "adapter null!!!!!!!!!!!!!!");
				adapter=new ExpandableSongAdapter(context, expandView, listSongs);
				expandView.setAdapter(adapter);
			}
			else{
				TagName.showLogError("Album", "adapter update_+______________");
				adapter.update(listSongs);
			}
	}
	// OnClickListener clickListener = new OnClickListener() {
	// @Override
	// public void onClick(View v) {
	// switch (v.getId()) {
	// case R.id.main_download:
	// if (songObject.getFormNet()) {
	// String url_path = songObject.getPATCH_FULL();
	// String songName = songObject.getTXNAME();
	// String nameSinger = songObject.getNAME_SINGERS();
	// DownloadTask downloadTask = new DownloadTask(context, url_path, songName,
	// nameSinger);
	// downloadTask.startDownload();
	// }
	// break;
	// case R.id.main_share:
	//
	// break;
	// case R.id.main_video:
	//
	// break;
	// case R.id.main_ringtone:
	//
	// break;
	//
	// default:
	// break;
	// }
	// }
	// };
}
